package com.hmall.search.mq;

import com.hmall.search.constatnts.MqConstants;
import com.hmall.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ItemListener {
    @Autowired
    private SearchService searchService;


    @RabbitListener(bindings=@QueueBinding(
            value= @Queue(MqConstants.ITEM_INSERT_QUEUE),
            exchange = @Exchange(value=MqConstants.ITEM_EXCHANGE,type = ExchangeTypes.DIRECT),
            key = MqConstants.ITEM_INSERT_KEY
    ))
    public void saveOrUpdateEs(String jsonString){
        searchService.saveOrUpdateEs(jsonString);
    }
    @RabbitListener(bindings=@QueueBinding(
            value= @Queue(MqConstants.ITEM_DELETE_QUEUE),
            exchange = @Exchange(value=MqConstants.ITEM_EXCHANGE,type = ExchangeTypes.DIRECT),
            key = MqConstants.ITEM_DELETE_KEY
    ))
    public void deleteEs(String id){
        searchService.deleteEs(id);
    }
}
